package com.jpxx.jpscp.core.base.service.serviceImpl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jpxx.jpscp.core.base.enitity.BaseEntity;
import com.jpxx.jpscp.core.base.service.BaseService;
import org.springframework.stereotype.Service;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @Description: 基于MyBatis-plus来实现Service接口的抽象Service
 * @author: Zhaopengfei
 * @copyright: 金鹏信息技术有限公司
 * @CreatedDate: 2018年03月14日 16:00
 * @Copyright: All rights Reserved，Designed By Jcn
 */
@Service
public class BaseServiceImpl<T extends BaseEntity> extends ServiceImpl<BaseMapper<T>, T> implements BaseService<T> {

    private Class<T> clazz;

    @SuppressWarnings("unchecked")
    public BaseServiceImpl() {
        super();
        // 获取父类的类型
        Type type = this.getClass().getGenericSuperclass();
        // 需要使用getActualTypeArguments，需要强转为ParameterizedType
        ParameterizedType pType = (ParameterizedType) type;
        // 获取泛型T的class
        this.clazz = (Class<T>) pType.getActualTypeArguments()[0];
    }


}
